﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using QuanLiThuVien.LinkModel;
using QuanLiThuVien.Model;

namespace QuanLiThuVien.Source
{
    class ShowInfo
    {
        THUVIEN.Service1 serv = new THUVIEN.Service1();
        private XuLyThem m_cXuLyThem = new XuLyThem();

        //public int ShowThamSo_KhoangCachNamXB()
        //{
        //    return serv.ShowThamSo_KhoangCachNamXB();
        //    if(serv.ShowThamSo_KhoangCachNamXB() == 0)
        //        MessageBox.Show("Canh bao", "Loi");
        //    else MessageBox.Show("Thanh Cong", "thanh cong");
        //}

        //public int ShowThamSo_NgayMuonToiDa()
        //{
        //    return serv.ShowThamSo_NgayMuonToiDa();
        //    if (serv.ShowThamSo_NgayMuonToiDa() == 0)
        //        MessageBox.Show("Canh bao", "Loi");
        //    else MessageBox.Show("Thanh Cong", "thanh cong");
        //}

        //public int ShowThamSo_SachMuonToiDa()
        //{
        //    return serv.ShowThamSo_SachMuonToiDa();
        //    if (serv.ShowThamSo_SachMuonToiDa() == 0)
        //        MessageBox.Show("Canh bao", "Loi");
        //    else MessageBox.Show("Thanh Cong", "thanh cong");
        //}

        //public int ShowThamSo_ThoiHanThe()
        //{
        //    return serv.ShowThamSo_ThoiHanThe();
        //    if (serv.ShowThamSo_ThoiHanThe() == 0)
        //        MessageBox.Show("Canh bao", "Loi");
        //    else MessageBox.Show("Thanh Cong", "thanh cong");
        //}

        //public int ShowThamSo_TienPhat()
        //{
        //    return serv.ShowThamSo_TienPhat();
        //    if (serv.ShowThamSo_TienPhat() == 0)
        //        MessageBox.Show("Canh bao", "Loi");
        //    else MessageBox.Show("Thanh Cong", "thanh cong");
        //}

        //public int ShowThamSo_TuoiToiThieu()
        //{
        //    return serv.ShowThamSo_TuoiToiThieu();
        //    if (serv.ShowThamSo_TuoiToiThieu() == 0)
        //        MessageBox.Show("Canh bao", "Loi");
        //    else MessageBox.Show("Thanh Cong", "thanh cong");
        //}

        //public int ShowThamSo_TuoiToiDa()
        //{
        //    return serv.ShowThamSo_TuoiToiDa();
        //    if (serv.ShowThamSo_TuoiToiThieu() == 0)
        //        MessageBox.Show("Canh bao", "Loi");
        //    else MessageBox.Show("Thanh Cong", "thanh cong");
        //}

        public void ShowListDocGia(DataGrid m_dtTheDocGia)
        {
            m_dtTheDocGia.ItemsSource = serv.ListDocGia();

            List<DSDocGia> dsDocGia = new List<DSDocGia>();
            for (int i = 0; i < serv.ListDocGia().Length; i++)
            {
                DSDocGia temp = new DSDocGia();

                temp.MaDocGia = serv.ListDocGia()[i].MaDocGia.ToString();
                temp.HoTenDocGia = serv.ListDocGia()[i].HoTenDocGia.ToString();
                temp.TenLoaiDocGia = serv.ListDocGia()[i].TenLoaiDocGia.ToString();
                temp.NgaySinh = DateTime.Parse(serv.ListDocGia()[i].NgaySinh.ToString());
                temp.DiaChi = serv.ListDocGia()[i].DiaChi.ToString();
                temp.Email = serv.ListDocGia()[i].Email.ToString();
                temp.NgayLapThe = DateTime.Parse(serv.ListDocGia()[i].NgayLapThe.ToString());
                temp.NgayHetHan = DateTime.Parse(serv.ListDocGia()[i].NgayHetHan.ToString());

                dsDocGia.Add(temp);
            }
            m_dtTheDocGia.ItemsSource = dsDocGia;
        }

        public void ShowListSach(DataGrid m_dtThongTinSach)
        {
            m_dtThongTinSach.ItemsSource = serv.ListThongTinSach();

            List<DSSach> dsThongTinSach = new List<DSSach>();
            for (int i = 0; i < serv.ListThongTinSach().Length; i++)
            {
                DSSach temp = new DSSach();
                temp.MaSach = serv.ListThongTinSach()[i].MaSach.ToString();
                temp.MaDauSach = serv.ListThongTinSach()[i].MaDauSach.ToString();
                temp.TenDauSach = serv.ListThongTinSach()[i].TenDauSach.ToString();
                temp.TenTheLoai = serv.ListThongTinSach()[i].TenTheLoai.ToString();
                temp.HoTenTacGia = serv.ListThongTinSach()[i].HoTenTacGia.ToString();
                temp.NhaXuatBan = serv.ListThongTinSach()[i].NhaXuatBan.ToString();
                temp.NamXuatBan = Int32.Parse(serv.ListThongTinSach()[i].NamXuatBan.ToString());
                temp.DonGia = Int32.Parse(serv.ListThongTinSach()[i].DonGia.ToString());
                temp.NgayLap = DateTime.Parse(serv.ListThongTinSach()[i].NgayLap.ToString());
                dsThongTinSach.Add(temp);
            }

            m_dtThongTinSach.ItemsSource = dsThongTinSach;
        }

        public void ShowListPhieuMuon(DataGrid m_dtPhieuMuon)
        {
            m_dtPhieuMuon.ItemsSource = serv.ListPhieuMuon();

            List<DSPhieuMuon> dsPhieuMuon = new List<DSPhieuMuon>();
            for (int i = 0; i < serv.ListPhieuMuon().Length; i++)
            {
                DSPhieuMuon temp = new DSPhieuMuon();
                temp.MaPhieuMuon = serv.ListPhieuMuon()[i].MaPhieuMuon.ToString();
                temp.MaDocGia = serv.ListPhieuMuon()[i].MaDocGia.ToString();
                temp.HoTenDocGia = serv.ListPhieuMuon()[i].HoTenDocGia.ToString();
                temp.MaCuonSach = serv.ListPhieuMuon()[i].MaCuonSach.ToString();
                temp.TenDauSach= serv.ListPhieuMuon()[i].TenDauSach.ToString();
                temp.TenTheLoai = serv.ListPhieuMuon()[i].TenTheLoai.ToString();
                temp.NhaXuatBan = serv.ListPhieuMuon()[i].NhaXuatBan.ToString();
                temp.NamXuatBan = Int32.Parse(serv.ListPhieuMuon()[i].NamXuatBan.ToString());
                temp.NgayMuon = DateTime.Parse(serv.ListPhieuMuon()[i].NgayMuon.ToString());
                temp.NgayPhaiTra = DateTime.Parse(serv.ListPhieuMuon()[i].NgayPhaiTra.ToString());
                dsPhieuMuon.Add(temp);
            }

            m_dtPhieuMuon.ItemsSource = dsPhieuMuon;
        }

        public void SelectDocGia(DataGrid m_dtTheDocGia, string HoTenDocGia)
        {
            m_dtTheDocGia.ItemsSource = serv.SelectDocGia(HoTenDocGia);

            List<DSDocGia> dsDocGia = new List<DSDocGia>();
            for (int i = 0; i < serv.SelectDocGia(HoTenDocGia).Length; i++)
            {
                DSDocGia temp = new DSDocGia();

                temp.MaDocGia = serv.SelectDocGia(HoTenDocGia)[i].MaDocGia.ToString();
                temp.HoTenDocGia = serv.SelectDocGia(HoTenDocGia)[i].HoTenDocGia.ToString();
                temp.TenLoaiDocGia = serv.SelectDocGia(HoTenDocGia)[i].TenLoaiDocGia.ToString();
                temp.NgaySinh = DateTime.Parse(serv.SelectDocGia(HoTenDocGia)[i].NgaySinh.ToString());
                temp.DiaChi = serv.SelectDocGia(HoTenDocGia)[i].DiaChi.ToString();
                temp.Email = serv.SelectDocGia(HoTenDocGia)[i].Email.ToString();
                temp.NgayLapThe = DateTime.Parse(serv.SelectDocGia(HoTenDocGia)[i].NgayLapThe.ToString());
                temp.NgayHetHan = DateTime.Parse(serv.SelectDocGia(HoTenDocGia)[i].NgayHetHan.ToString());

                dsDocGia.Add(temp);
            }
            m_dtTheDocGia.ItemsSource = dsDocGia;
        }

        public void ShowListBCMuonSach(DataGrid m_dtBCMuonSach)
        {
            m_dtBCMuonSach.ItemsSource = serv.ListBCMuonSach();

            List<DSBCMuonSach> dsBDMuonSach = new List<DSBCMuonSach>();
            for (int i = 0; i < serv.ListBCMuonSach().Length; i++)
            {
                DSBCMuonSach temp = new DSBCMuonSach();
                temp.MaTheLoai = serv.ListBCMuonSach()[i].MaTheLoai.ToString();
                temp.TenTheLoai = serv.ListBCMuonSach()[i].TenTheLoai.ToString();
                temp.Thang = Int32.Parse(serv.ListBCMuonSach()[i].Thang.ToString());
                temp.Nam = Int32.Parse(serv.ListBCMuonSach()[i].Nam.ToString());
                temp.LuotMuon = Int32.Parse(serv.ListBCMuonSach()[i].LuotMuon.ToString());
                temp.TongLuotMuon = Int32.Parse(serv.ListBCMuonSach()[i].TongLuotMuon.ToString());
                temp.TiLe = float.Parse(serv.ListBCMuonSach()[i].TiLe.ToString());
                dsBDMuonSach.Add(temp);
            }

            m_dtBCMuonSach.ItemsSource = dsBDMuonSach;
        }

        public void SelectBCMuonSach(DataGrid m_dtBCMuonSach, string MaBCMS)
        {
            m_dtBCMuonSach.ItemsSource = serv.SelectBCMuonSach(MaBCMS);

            List<DSBCMuonSach> dsBCMuonSach = new List<DSBCMuonSach>();
            for (int i = 0; i < serv.SelectBCMuonSach(MaBCMS).Length; i++)
            {
                DSBCMuonSach temp = new DSBCMuonSach();
                temp.MaTheLoai = serv.SelectBCMuonSach(MaBCMS)[i].MaTheLoai.ToString();
                temp.TenTheLoai = serv.SelectBCMuonSach(MaBCMS)[i].TenTheLoai.ToString();
                temp.Thang = Int32.Parse(serv.SelectBCMuonSach(MaBCMS)[i].Thang.ToString());
                temp.Nam = Int32.Parse(serv.SelectBCMuonSach(MaBCMS)[i].Nam.ToString());
                temp.LuotMuon = Int32.Parse(serv.SelectBCMuonSach(MaBCMS)[i].LuotMuon.ToString());
                temp.TongLuotMuon = Int32.Parse(serv.SelectBCMuonSach(MaBCMS)[i].TongLuotMuon.ToString());
                temp.TiLe = float.Parse(serv.SelectBCMuonSach(MaBCMS)[i].TiLe.ToString());
                dsBCMuonSach.Add(temp);
            }
            m_dtBCMuonSach.ItemsSource = dsBCMuonSach;
        }

        public void SelectBCTraTre(DataGrid m_dtBCTraTre, DateTime NgayTra)
        {
            m_dtBCTraTre.ItemsSource = serv.SelectBCTraTre(NgayTra);

            List<DSBCTraTre> dsBCTraTre = new List<DSBCTraTre>();
            for (int i = 0; i < serv.SelectBCTraTre(NgayTra).Length; i++)
            {               
                DSBCTraTre temp = new DSBCTraTre();
                temp.MaCuonSach = serv.SelectBCTraTre(NgayTra)[i].MaCuonSach.ToString();
                temp.TenDauSach = serv.SelectBCTraTre(NgayTra)[i].TenDauSach.ToString();
                temp.NgayMuon = DateTime.Parse(serv.SelectBCTraTre(NgayTra)[i].NgayMuon.ToString());
                temp.NgayPhaiTra = DateTime.Parse(serv.SelectBCTraTre(NgayTra)[i].NgayPhaiTra.ToString());
                temp.NgayTra = DateTime.Parse(serv.SelectBCTraTre(NgayTra)[i].NgayTra.ToString());
                temp.SoNgayMuon = Int32.Parse(serv.SelectBCTraTre(NgayTra)[i].SoNgayMuon.ToString());
                temp.SoNgayTraTre = m_cXuLyThem.KhoangCachHaiNgay(temp.NgayPhaiTra, temp.NgayTra);
                dsBCTraTre.Add(temp);

                serv.InsertBCTraTre(temp.NgayTra, temp.MaCuonSach, temp.NgayMuon, temp.SoNgayTraTre);
            }
            m_dtBCTraTre.ItemsSource = dsBCTraTre;
        }

        public void ListSachMatHong(DataGrid m_dtThongTinSach, int TinhTrang)
        {
            m_dtThongTinSach.ItemsSource = serv.ListSachMatHong(TinhTrang);

            List<DSSach> dsThongTinSach = new List<DSSach>();
            for (int i = 0; i < serv.ListSachMatHong(TinhTrang).Length; i++)
            {
                DSSach temp = new DSSach();
                temp.MaSach = serv.ListSachMatHong(TinhTrang)[i].MaSach.ToString();
                temp.TenDauSach = serv.ListSachMatHong(TinhTrang)[i].TenDauSach.ToString();
                temp.TenTheLoai = serv.ListSachMatHong(TinhTrang)[i].TenTheLoai.ToString();
                temp.HoTenTacGia = serv.ListSachMatHong(TinhTrang)[i].HoTenTacGia.ToString();
                temp.NhaXuatBan = serv.ListSachMatHong(TinhTrang)[i].NhaXuatBan.ToString();
                temp.NamXuatBan = Int32.Parse(serv.ListSachMatHong(TinhTrang)[i].NamXuatBan.ToString());
                temp.DonGia = Int32.Parse(serv.ListSachMatHong(TinhTrang)[i].DonGia.ToString());
                dsThongTinSach.Add(temp);
            }

            m_dtThongTinSach.ItemsSource = dsThongTinSach;
        }

        public void ShowListNhanVien(DataGrid m_dtNhanVien)
        {
            m_dtNhanVien.ItemsSource = serv.ListNhanVien();

            List<DSNhanVien> dsNhanVien = new List<DSNhanVien>();
            for (int i = 0; i < serv.ListNhanVien().Length; i++)
            {
                DSNhanVien temp = new DSNhanVien();

                temp.MaNhanVien = serv.ListNhanVien()[i].MaNhanVien.ToString();
                temp.HoTenNhanVien = serv.ListNhanVien()[i].HoTenNhanVien.ToString();
                temp.MaLoaiNhanVien = serv.ListNhanVien()[i].MaLoaiNhanVien.ToString();
                temp.TenLoaiNhanVien = serv.ListNhanVien()[i].TenLoaiNhanVien.ToString();

                dsNhanVien.Add(temp);
            }
            m_dtNhanVien.ItemsSource = dsNhanVien;
        }



        public void ShowListTheLoai(DataGrid m_dtTheLoai)
        {
            m_dtTheLoai.ItemsSource = serv.ListTheLoai();

            List<TheLoai> dsTheLoai = new List<TheLoai>();
            for (int i = 0; i < serv.ListTheLoai().Length; i++)
            {
                TheLoai temp = new TheLoai();

                temp.MaTheLoai = serv.ListTheLoai()[i].MaTheLoai.ToString();
                temp.TenTheLoai = serv.ListTheLoai()[i].TenTheLoai.ToString();

                dsTheLoai.Add(temp);
            }
            m_dtTheLoai.ItemsSource = dsTheLoai;
        }
    }
}
